<template>
  <div class="realname-info">
    <div class="container">
      <div class="model-title">待审核列表 (<span v-html="type==='realname'?'实名审核':'商户审核'"></span>) </div>
      <div class="list-box" v-loading="loading">
          <div class="oprate-box">
            <el-select @change="handleStatus" v-model="type" >
                <el-option
                v-for="item in statusList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
                </el-option>
            </el-select>
          </div>
          <div class="realname-list" v-if="type==='realname'" >
              <el-table
                  :data="member_list"
                  style="width: 100%">
                  <el-table-column
                    v-for="cell in member_list_header" :key="cell.prop"
                    :prop="cell.prop"
                    :label="cell.label"
                    :formatter = formatterList
                    >
                  </el-table-column>
                  <el-table-column
                    fixed="right"
                    label="操作"
                    width="80">
                    <template slot-scope="scope">
                      <el-button type="text" @click="handleRealname(scope.row)" size="small">审核</el-button>
                    </template>
                  </el-table-column>
                </el-table>
          </div>
          <div class="shop-list" v-if="type==='shop'">
             <el-table
                :data="shop_list"
                style="width: 100%">
                <el-table-column
                  v-for="cell in shop_list_header" :key="cell.prop"
                  :prop="cell.prop"
                  :label="cell.label"
                  :formatter = formatterListShop
                  >
                </el-table-column>
                <el-table-column
                    fixed="right"
                    label="操作"
                    width="80">
                    <template slot-scope="scope">
                      <el-button type="text" @click="handleShop(scope.row)" size="small">审核</el-button>
                    </template>
                  </el-table-column>
              </el-table>


          </div>
          <div>
            <div class="pages-control">
                  <el-pagination
                    @current-change="handleCurrentChange"
                    :current-page.sync="pages.currentPage+1"
                    :page-size="pages.page_size"
                    layout="prev, pager, next, jumper"
                    :total="pages.total">
                  </el-pagination>
              </div>
          </div>
      </div>
    </div>
  </div>
</template>

<script>

function formatterTime(value) {//value为13位的时间戳
    function add0(m) {
        return m < 10 ? '0' + m : m
    }
    var time = new Date(parseInt(value));
    var y = time.getFullYear();
    var m = time.getMonth() + 1;
    var d = time.getDate();
    return y + '-' + add0(m) + '-' + add0(d);
}

function formatterShop(value){
    if(value == 0){
        return value = "消费者"
    }
    if(value == 1){
        return value = "分销商"
    }
    if(value == 2){
        return value = "代理商"
    }
    if(value == 3){
        return value = "服务商"
    }
}
function formatterRealname(value){
    if(value == 0){
        return value = "未审核  ❓"
    }
    if(value == 1){
        return value = "审核中  ❗"
    }
    if(value == 2){
        return value = "审核失败❌"
    }
    if(value == 3){
        return value = "即付审核中 ❗"
    }
    if(value == 4){
        return value = "即付审核失败 ❌"
    }
    if(value == 5){
        return value = "未提交  ❗"
    }
}


export default {
  name:'realname-info',
  data () {
    return {
       type:"realname",
       loading:false,
       statusList:[
         {value:"realname",label:"待实名审核列表"},
          {value:"shop",label:"待商户审核列表"},
       ],
       member_list:[],
       member_list_header:[
          {prop:"createTime",label:"注册日期"},
          {prop:"brandName",label:"品牌名称"},
          {prop:"realname",label:"真实姓名"},
          {prop:"phone",label:"手机号码"},
          {prop:"realnameStatus",label:"实名状态"},
          {prop:"grade",label:"代理等级"},
        //   {prop:"usershopStatus",label:"商户状态"}
       ],
       shop_list:[],
       shop_list_header:[
          {prop:"shopName",label:"商户名称"},
          {prop:"shopId",label:"商户号"},
          {prop:"shopProvinces",label:"所在省市"},
          {prop:"shopUserName",label:"联系人"},
          {prop:"mobilePhone",label:"联系电话"},
          {prop:"createTime",label:"创建时间"},
          {prop:"status",label:"审核状态"}
       ],
       pages:{
          total:1000,
          page_size:20,
          currentPage:0
        }
    };
  },
  components: {},
  created() {
    this.type = this.$route.params.type || 'realname';
    this.handleStatus();
  },
  mounted() {},
  methods: {
    handleStatus(){
        // 获取对应得列表
        if(this.type ==="realname"){
          this.getRealname()
          return;
        }
        if(this.type === 'shop'){
          this.getShop()
        }
    },
    getRealname(){
      // 获取待审核列表
     
      let params = `roleId=1&realnameStatus=0`;
      let token = sessionStorage.getItem(1);
      let url = `user/afer/${token}`;
      this.loading = true;
      this.$Http.post(url,params).then(res=>{
         this.loading = false;
          if(res.data.resp_code === "000000"){    
              if(res.data.result.length<=0){
                  this.$notify.info({
                    title: '消息',
                    message: "暂无下级会员！"
                  }); 
              }else{
                  this.member_list = res.data.result.content;
                  this.pages.total = res.data.result.totalElememts;
              }
          }else{
            this.$notify.info({
              title: '消息',
              message: res.data.resp_message
            }); 
          } 
        }).catch(err=>{
            this.loading = false;
            this.$notify.error({
              title: '错误',
              message: '获取信息失败！'
            });
        });
    },
    getShop(){
       let url = `user/shop/findVerify`;
           let params = `?page=${this.pages.currentPage}&size=${this.pages.page_size}`;
            this.loading = true;
            this.$Http.get(url+params).then(res=>{
                this.loading = false;
                if(res.data.resp_code === "000000"){
                    this.shop_list = res.data.result.content;
                    this.pages.total = res.data.result.totalElememts;
                    if(res.data.result.content.length<=0){
                        this.$notify.info({
                        title: '消息',
                        message: "暂无商户信息！"
                        }); 
                    }
                }else{
                this.$notify.info({
                    title: '消息',
                    message: res.data.resp_message
                }); 
                } 
            }).catch(err=>{
                this.loading = false;
                this.$notify.error({
                    title: '错误',
                    message: '获取信息失败！'
                });
            })
    },
    handleCurrentChange(value){

    },
    handleRealname(cell){
       // 实名审核\
       this.$router.push({
         name:"checkRealname",
         params:{
           phone:cell.phone
         }
       })
    },
    handleShop(cell){
        // 商户审核
      this.$router.push({
         name:"shopAuthDetail",
         params:{
           shopId:cell.shopId
         }
       })
    },
    formatterListShop(row, column, cellValue, index){
      if(column.label === "创建时间"){
          return formatterTime(cellValue);
      }else if(column.label === "审核状态"){
        return formatterRealname(cellValue)
      }else{
         return cellValue===null?'--':cellValue;
      }
    },
    formatterList(row, column, cellValue, index){
       //  格式化信息
      if(column.label === "注册日期"){
          return formatterTime(cellValue);
      }else if(column.label === "实名状态"){
          return formatterRealname(cellValue)
      }else if(column.label === "代理等级"){
          return "LV."+cellValue;
      }else if(column.label === "商户状态"){
        //  return formatterShop(cellValue);
        return '商户'
      }else{
         return cellValue===null?'--':cellValue;
      }
    }
  }
}

</script>
<style scoped>
tr,.cell{
  cursor: pointer;
}
.pages-control{
  display: flex;
  justify-content: center;
}
</style>